package ru.xpparty.scanner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import ru.xpparty.scanner.model.ScanRequest;

/**
 * Created by IntelliJ IDEA.
 * User: Grab
 * Date: 19.12.10
 * Time: 17:57
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException, FileNotFoundException, IOException {
        ArgumentsBuilder builder = new ArgumentBuilderImpl();
        ScanRequest request = builder.build(args);
        Scanner scanner = new Scanner();
        scanner.setSocketScannerFactory(new SocketScannerFactory() {
            @Override
            public SocketScanner create(String host, int port) {
                return new SocketScanner(host, port);
            }
        });
        Properties props = new Properties();
        props.load(new FileInputStream("scanner.config"));
        
        long start = System.currentTimeMillis();
        ExecutorService pool = Executors.newFixedThreadPool(Integer.parseInt((String) props.get("threads.count")));
        scanner.setExecutorService(pool);
        ScanResult result = scanner.scan(request);
        pool.shutdown();
        long end = System.currentTimeMillis();
        System.out.println(result.toString());
        System.out.println(String.format("Scan performed in %d millis", end - start));
    }
}
